/*
 * @Descripttion: 
 * @Author: ziwei
 * @Date: 2022-07-06 15:11:51
 * @LastEditors: ziwei
 * @LastEditTime: 2022-07-06 15:13:58
 */
interface Bird{
    leg:number
  }
  interface Dog{
    leg:number
  }
  function getNumber(x:Bird|Dog){
    if('swing' in x){
        console.log(x);
    }else{
        console.log(x)
    }
  }

  //自定义的类型保护 有难度！！
  //类型保护就是表达式，运行时进行类型检查，保证作用域内类型是符合预期的

//   function isType(type:Type1|Type2):type is Type1{
//   }
//类型谓词 parameterName is Type哪个参数是什么类型
function isBird(x:Bird|Dog):x is Bird{
    return x.leg == 2;
}

function getAnimal(x:Bird|Dog){
    if(isBird(x)){
        console.log(x)
    }else{
        console.log(x)
    }
}